package com.algoruthm6;

import java.util.Arrays;

public class BubbleSort {

    public static void sort(int[] array){
        for(int i=1;i<array.length;i++){
            boolean shouldSwap = false;
            for(int j=0;j<array.length-i;j++){
               if(array[j]>array[j+1]){
                   Utils.swap(array,j,j+1);
                   shouldSwap = true;
               }
            }
            if(!shouldSwap){
                return;
            }
            System.out.println("i="+i+"-->"+ Arrays.toString(array));
        }

    }

    public static void main(String[] args){
        int[] array = new int[]{4,3,6,8,9,7,10,5,1,2};
        System.out.println("array:"+ Arrays.toString(array));
        sort(array);
        System.out.println("sorted array:"+ Arrays.toString(array));
    }
}
